<?php
/**
 * Maincategoryadmin_Data_Editmaincategory
 * set edit main category template vairables
 * @author Adrian Stolarski
 */
class Maincategoryadmin_Data_Editmaincategory implements Maincategoryadmin_Data_Mainable, 
        Maincategoryadmin_Data_Preparable, Maincategoryadmin_Data_Templatable, 
        Maincategoryadmin_Data_Tokenable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    /**
     *
     * @var type $current_module_data
     * current module data handler
     */
    public $current_module_data;
    /**
     *
     * @var type $random_token
     * random token handler 
     */
    public $random_token;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
        $this->current_module_data = new Core_Controller_Currentmoduledata;
        $this->random_token = new Core_Data_Tokenizer;
    }
    
    /**
     * main()
     * get page tempalte data
     * 
     * @param array $variables
     * @return type $page
     */
    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $page['template'] = $this->get_template_name();
        //var_dump($page);
        //die();
        $page['csrf_token'] = $this->create_token();
        //var_dump($page);
        //die();
        $page['main_category_data'] = $this->database->fetch('array');
        //var_dump($page);
        //die();
        $page['current_module_data'] = array();
        $page['current_module_data'] = $this->current_module_data->main($page['main_category_data']);
        //var_dump($page);
        //die();
        return $page;
    }
    
    /**
     * prepare_query()
     * get current main category data
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database_query = "SELECT * FROM page_main_category WHERE main_category_name='".$variables['main_category_name']."';";
        //echo $this->database_query;
        //die();
    }
    
    /**
     * create_token()
     * create random token
     * 
     * @return type $random_token
     */
    public function create_token() {
        return $this->random_token->create_token();
    }
    
    /**
     * get_template_name()
     * get current template name
     * 
     * @return string $template
     */
    public function get_template_name() {
        $template = SERVER_ROOT."maincategoryadmin/views/editmaincategory.php";
        return $template;
    }

}
